import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
import useMediaQuery from "@mui/material/useMediaQuery";
import React, { useState, useMemo } from "react";
import { useTranslation } from "react-i18next";
import { useSelector } from "react-redux";
import { matchTheme, formateDate, dateCompare, walletRootRef } from "../../../utils";
import classes from "./eventCard.module.less";
import classNames from "classnames";
import { LocalKeyMap } from "../../../local";
import { useClipboard } from "use-clipboard-copy";
import toast from "../../../compoents/toast";
import Barcode from "react-jsbarcode";
import { QRCodeSVG } from "qrcode.react";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
import { Fragment as _Fragment } from "react/jsx-runtime";
var formatEventDate = function(date) {
    return formateDate(date, "DD MMM YYYY");
};
var EventCard = function(props) {
    var _useState = _sliced_to_array(useState(false), 2), ruleOpen = _useState[0], setRuleOpen = _useState[1];
    var isPc = useMediaQuery("(min-width:1280px)");
    var t = useTranslation().t;
    var codeStr = props.code || "";
    var isCode = /qrcode:\/\//.test(codeStr);
    var isCdkey = /(text|cdkey):\/\//.test(codeStr);
    // text://
    // cdkey://
    var codeArray = (codeStr === null || codeStr === void 0 ? void 0 : codeStr.split(/(^[a-zA-Z]*:\/\/)/)) || [];
    var theme = useSelector(function(rt) {
        return rt.app.theme;
    });
    var copy = useClipboard({
        onSuccess: function onSuccess() {
            toast.copy();
        },
        onError: function onError() {
            toast.createToast({
                type: "errToast",
                message: "copy error"
            });
        }
    }).copy;
    var size = useMemo(function() {
        if (isPc) return 15.2;
        return "var(--m12)";
    }, [
        isPc
    ]);
    // const openQR = () => {
    //   if (type !== 'available') return;
    //   const QRToastOption = toast({
    //     content: (
    //       <UtilityQR
    //         imgUrl={props.logoUrl}
    //         onClose={destoryQR}
    //         qrContent={props.qrCode}
    //       />
    //     ),
    //     duration: -1,
    //     mask: true,
    //     centered: true,
    //   });
    //   function destoryQR() {
    //     QRToastOption.destroy();
    //   }
    // };
    var openCode = function() {
        var _ref = _async_to_generator(function() {
            var codeModal;
            return _ts_generator(this, function(_state) {
                codeModal = toast({
                    content: /*#__PURE__*/ _jsxs("div", {
                        className: classes.codeWrap,
                        children: [
                            /*#__PURE__*/ _jsxs("div", {
                                className: classes.codeInner,
                                children: [
                                    /*#__PURE__*/ _jsx("div", {
                                        className: classes.codeHeader,
                                        children: /*#__PURE__*/ _jsx("div", {
                                            className: classes.codeTit,
                                            children: "SUB-NFT Code"
                                        })
                                    }),
                                    /*#__PURE__*/ _jsxs("div", {
                                        className: classes.codeBody,
                                        children: [
                                            /*#__PURE__*/ _jsxs("div", {
                                                className: classes.codeBox,
                                                style: {
                                                    display: isCode ? "flex" : "none"
                                                },
                                                children: [
                                                    /*#__PURE__*/ _jsx(Barcode, {
                                                        className: classes.barCode,
                                                        options: {
                                                            format: "code128",
                                                            displayValue: false,
                                                            background: "transparent",
                                                            margin: 0,
                                                            width: 4
                                                        },
                                                        value: codeArray[2]
                                                    }),
                                                    /*#__PURE__*/ _jsx(QRCodeSVG, {
                                                        value: codeArray[2],
                                                        className: classes.qrCode,
                                                        level: "M",
                                                        bgColor: "transparent",
                                                        fgColor: "#000"
                                                    })
                                                ]
                                            }),
                                            /*#__PURE__*/ _jsxs("div", {
                                                className: classes.codeText,
                                                style: {
                                                    display: isCdkey ? "flex" : "none"
                                                },
                                                children: [
                                                    /*#__PURE__*/ _jsx("span", {
                                                        className: classes.text,
                                                        children: codeArray[2]
                                                    }),
                                                    /*#__PURE__*/ _jsx("img", {
                                                        onClick: function() {
                                                            copy(codeArray[2]);
                                                        },
                                                        className: classes.icon,
                                                        src: matchTheme(theme, {
                                                            light: require("../../../assets/icons/light/copy.svg"),
                                                            dark: require("../../../assets/icons/dark/copy.svg")
                                                        })
                                                    })
                                                ]
                                            })
                                        ]
                                    })
                                ]
                            }),
                            /*#__PURE__*/ _jsx("img", {
                                onClick: function() {
                                    codeModal.destroy();
                                },
                                className: classes.codeClose,
                                src: require("../../../assets/icons/close.svg"),
                                alt: ""
                            })
                        ]
                    }),
                    duration: -1,
                    maskColor: "rgba(0, 0, 0, .7)",
                    mask: true,
                    centered: true,
                    inner: true,
                    container: walletRootRef.current,
                    maskZIndex: 100
                });
                return [
                    2
                ];
            });
        });
        return function openCode() {
            return _ref.apply(this, arguments);
        };
    }();
    var comingSoon = function() {
        toast({
            content: /*#__PURE__*/ _jsx(_Fragment, {
                children: /*#__PURE__*/ _jsx("div", {
                    className: classes.comingSoon,
                    children: t(LocalKeyMap.comingSoon)
                })
            }),
            duration: 2000,
            mask: false,
            centered: true,
            inner: true,
            container: walletRootRef.current,
            maskZIndex: 1401
        });
    };
    var openDetail = function() {
        var rule = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "";
        var destroy = toast({
            content: /*#__PURE__*/ _jsxs(_Fragment, {
                children: [
                    /*#__PURE__*/ _jsxs("div", {
                        className: classes.subDetail,
                        children: [
                            /*#__PURE__*/ _jsx("div", {
                                className: classes.hd,
                                children: "Details"
                            }),
                            /*#__PURE__*/ _jsx("div", {
                                className: classes.bd,
                                children: rule
                            })
                        ]
                    }),
                    /*#__PURE__*/ _jsx("div", {
                        className: classes.subDetailClose,
                        onClick: function() {
                            destroy();
                        },
                        children: /*#__PURE__*/ _jsx("img", {
                            src: require("../../../assets/icons/close.svg"),
                            alt: ""
                        })
                    })
                ]
            }),
            duration: -1,
            mask: true,
            centered: true,
            inner: true,
            container: walletRootRef.current,
            maskZIndex: 1401
        }).destroy;
    };
    var type = useMemo(function() {
        /** 进行中 */ if (dateCompare.isBetween(props.currentTime, props.startTime, props.endTime, "m", "[)")) return "today";
        /** 未开始 */ if (dateCompare.isBefore(props.currentTime, props.startTime, "m")) return "upcoming";
        /** 已失效 */ return "unavailable";
    }, [
        props.startTime,
        props.endTime
    ]);
    /** 判断是否在列表是显示或者隐藏 */ var show = useMemo(function() {
        if (props.eventType === "today") {
            return type === "today";
        }
        if (props.eventType === "upcoming") {
            return type === "upcoming";
        }
        return true;
    }, [
        props.eventType,
        type
    ]);
    return show && /*#__PURE__*/ _jsxs("div", {
        className: classNames(classes.event_card, props.disabled ? classes.disabled : ""),
        children: [
            /*#__PURE__*/ _jsxs("div", {
                className: classes.event_head,
                children: [
                    /*#__PURE__*/ _jsx("div", {
                        className: classes.event_title,
                        children: props.name
                    }),
                    /*#__PURE__*/ _jsx("div", {
                        className: classes.event_avatar,
                        children: /*#__PURE__*/ _jsx("img", {
                            src: props.logoUrl
                        })
                    }),
                    /*#__PURE__*/ _jsx("img", {
                        className: classes.event_list_v3,
                        src: require("../../../assets/icons/split.svg")
                    }),
                    props.effectiveTimes > 1 ? /*#__PURE__*/ _jsx("div", {
                        className: classes.counter,
                        children: /*#__PURE__*/ _jsx("span", {
                            children: props.effectiveTimes
                        })
                    }) : null,
                    /*#__PURE__*/ _jsx("div", {
                        className: "".concat(classes.subNft, " ").concat(theme === "dark" && classes.dark),
                        children: "SUB-NFT"
                    })
                ]
            }),
            /*#__PURE__*/ _jsxs("div", {
                className: classes.event_body,
                children: [
                    /*#__PURE__*/ _jsx("div", {
                        className: classes.event_info,
                        children: /*#__PURE__*/ _jsxs("div", {
                            className: classes.event_details,
                            children: [
                                /*#__PURE__*/ _jsxs("div", {
                                    className: classes.event_item,
                                    children: [
                                        /*#__PURE__*/ _jsx("img", {
                                            className: classes.event_item_icon,
                                            src: props.disabled ? require("../../../assets/icons/disabledBrand.svg") : matchTheme(theme, {
                                                light: require("../../../assets/icons/light/brand.svg"),
                                                dark: require("../../../assets/icons/dark/brand.svg")
                                            })
                                        }),
                                        /*#__PURE__*/ _jsx("span", {
                                            className: classes.event_icon_value,
                                            children: props.organizerName
                                        })
                                    ]
                                }),
                                /*#__PURE__*/ _jsxs("div", {
                                    className: classes.event_item,
                                    children: [
                                        /*#__PURE__*/ _jsx("img", {
                                            className: classes.event_item_icon,
                                            src: props.disabled ? require("../../../assets/icons/disabledLocation.svg") : matchTheme(theme, {
                                                light: require("../../../assets/icons/light/location.svg"),
                                                dark: require("../../../assets/icons/dark/location.svg")
                                            })
                                        }),
                                        /*#__PURE__*/ _jsx("span", {
                                            className: classNames(classes.event_icon_value),
                                            children: /*#__PURE__*/ _jsx("a", {
                                                target: "_blank",
                                                rel: "noreferrer",
                                                href: props.link,
                                                className: "".concat(classes.event_link, " ").concat(theme === "dark" ? classes.dark : ""),
                                                children: props.address
                                            })
                                        })
                                    ]
                                }),
                                /*#__PURE__*/ _jsxs("div", {
                                    className: classes.event_item,
                                    children: [
                                        /*#__PURE__*/ _jsx("img", {
                                            className: classes.event_item_icon,
                                            src: props.disabled ? require("../../../assets/icons/disabledDate.svg") : matchTheme(theme, {
                                                light: require("../../../assets/icons/date.svg"),
                                                dark: require("../../../assets/icons/dark/date.svg")
                                            })
                                        }),
                                        /*#__PURE__*/ _jsxs("span", {
                                            className: classes.event_icon_value,
                                            children: [
                                                formatEventDate(props.startTime),
                                                " - ",
                                                formatEventDate(props.endTime)
                                            ]
                                        })
                                    ]
                                }),
                                /*#__PURE__*/ _jsxs("div", {
                                    className: classes.event_item,
                                    children: [
                                        /*#__PURE__*/ _jsx("img", {
                                            className: classes.event_item_icon,
                                            src: props.disabled ? require("../../../assets/icons/disabledRegion.svg") : matchTheme(theme, {
                                                light: require("../../../assets/icons/light/region.svg"),
                                                dark: require("../../../assets/icons/dark/region.svg")
                                            })
                                        }),
                                        /*#__PURE__*/ _jsx("span", {
                                            className: classes.event_icon_value,
                                            children: props.region
                                        })
                                    ]
                                })
                            ]
                        })
                    }),
                    /*#__PURE__*/ _jsxs("div", {
                        className: "".concat(classes.eventMeta, " ").concat(theme === "dark" && classes.dark),
                        children: [
                            /*#__PURE__*/ _jsx("div", {
                                className: classes.icon,
                                onClick: function() {
                                    comingSoon();
                                },
                                children: /*#__PURE__*/ _jsx("img", {
                                    src: matchTheme(theme, {
                                        dark: require("../../../assets/icons/dark/send.svg"),
                                        light: require("../../../assets/icons/light/send.svg")
                                    })
                                })
                            }),
                            /*#__PURE__*/ _jsx("div", {
                                className: classes.icon,
                                onClick: function() {
                                    comingSoon();
                                },
                                children: /*#__PURE__*/ _jsx("img", {
                                    src: matchTheme(theme, {
                                        dark: require("../../../assets/icons/dark/marketplace.svg"),
                                        light: require("../../../assets/icons/light/marketplace.svg")
                                    })
                                })
                            }),
                            /*#__PURE__*/ _jsx("div", {
                                className: classes.icon,
                                onClick: function() {
                                    comingSoon();
                                },
                                children: /*#__PURE__*/ _jsx("img", {
                                    src: matchTheme(theme, {
                                        dark: require("../../../assets/icons/dark/buyBack.svg"),
                                        light: require("../../../assets/icons/light/buyBack.svg")
                                    })
                                })
                            }),
                            /*#__PURE__*/ _jsx("div", {
                                className: classes.icon,
                                onClick: function() {
                                    openDetail(props.rules);
                                },
                                children: /*#__PURE__*/ _jsx("img", {
                                    src: matchTheme(theme, {
                                        dark: require("../../../assets/icons/dark/infoCircle.svg"),
                                        light: require("../../../assets/icons/light/infoCircle.svg")
                                    })
                                })
                            }),
                            props.code && /*#__PURE__*/ _jsx("div", {
                                className: "".concat(classes.icon),
                                onClick: function() {
                                    openCode();
                                },
                                children: /*#__PURE__*/ _jsx("img", {
                                    src: matchTheme(theme, {
                                        dark: require("../../../assets/icons/dark/key.svg"),
                                        light: require("../../../assets/icons/light/key.svg")
                                    })
                                })
                            })
                        ]
                    })
                ]
            })
        ]
    });
};
export default EventCard;

 //# sourceMappingURL=index.js.map